package com.xuan.controller;

import com.xuan.entity.po.UserRoles;
import com.xuan.entity.result.Result;
import com.xuan.service.IUserRolesService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class PermissionController {
    private final IUserRolesService userRolesService;
    @GetMapping("/{userId}")
    public Result<String> getUserRoleCode(@PathVariable Long userId) {
        return userRolesService.getUserRoleCode(userId);
    }

    // 绑定默认角色（普通用户）
    @GetMapping("/bindDefaultRole/{userId}")
    public void bindDefaultRole(@PathVariable Long userId){
        userRolesService.bindDefaultRole(userId);
    }

    // 超管调用：升级用户为管理员
    @GetMapping("/upgradeToAdmin/{userId}")
    public void upgradeToAdmin(@PathVariable Long userId){
        userRolesService.upgradeToAdmin(userId);
    }

    // 超管调用：降级用户为普通角色
    @GetMapping("/downgradeToUser/{userId}")
    public void downgradeToUser(@PathVariable Long userId){
        userRolesService.downgradeToUser(userId);
    }

    // 管理员调用:查询所有普通用户的id
    @GetMapping("/getAllCommonUser")
    public Result<List<Long>> getAllCommonUser(){
        return userRolesService.getAllCommonUser();
    }

    // 超管调用: 查询所有用户
    @GetMapping("/getAllUser")
    public Result<List<UserRoles>> getAllUser(){
        return userRolesService.getAllUser();
    }
}
